Notice that we have a single, synchronous service
operation defined. This operation accepts an adverse event, and returns
the resulting action that the submitter should take.
We now need an
actual service implementation of this interface. In a separate class
file, I have my very simple service that looks like this:
public AdverseEventAction SubmitAdverseEvent(AdverseEvent NewAE)
{
AdverseEventAction AEAction = new AdverseEventAction();
AEAction.SubmissionID = Guid.NewGuid().ToString();
AEAction.PatientID = NewAE.PatientID;
AEAction.Product = NewAE.Product;
//initialize values
AEAction.doAdmitHospital = false;
AEAction.doCeaseMedication = false;
AEAction.doReduceDosage = false;
AEAction.doScheduleFollowup = false;
AEAction.AdditionalNotes = "";
TimeSpan aeDuration= DateTime.Now.Subtract(NewAE.DateStarted);
if (NewAE.Category == AECategoryType.InjectionSoreness && aeDuration.Days > 3)
{
AEAction.doReduceDosage = true;
}
return AEAction;
}
For this basic scenario,
we're checking to see if someone is still experiencing soreness more
than three days after a drug injection. Our next step is to actually
host this WCF service, so that it is visible to the outside world. Up
until now, we've focused primarily on self-hosting, but I'm going to
switch gears and take advantage of IIS 7.0 and Windows Process
Activation Services (WAS) for hosting our WCF services.
Let's add a WCF Service Web Site project to our existing Visual Studio.NET solution.
Once again, we are
provided some sample classes and implementation objects by this Visual
Studio.NET project type. We can freely delete the Service1.cs
class files as we won't be putting actual service implementation logic
into this host container. Next, we have to add a reference to our
existing WCF service library project. After that, we change the
directive at the top of the Service.svc file so that it points to the service type residing in our referenced library. That single line at the top should read:
<%@ ServiceHost Language="C#" Debug="true" Service="Seroter.BizTalkSOA.Chapter6.ServiceLibrary. AdverseEventSyncService" %>
Almost there. All that remains to do is use the WCF Service Configuration Editor to update the web.config
file to accurately reflect our referenced service configuration. We
only need to modify the service name and the endpoint contract.
You may notice that we do not
need to add either a base address or service address in order for this
service configuration to be complete. When a service is hosted within
IIS 7.0, the base address is equal to the address of the .svc file.
We can confirm a successful configuration by opening IIS 7.0, locating our new service, and browsing the .svc file. You should see the standard WCF service introduction page.